<?php
class ClassDateTime
{
	function _formatDateYMDtoMDY($stringdate,$format)
	{
		return $this->getmonth($stringdate).$format.$this->getday($stringdate).$format.$this->getyear($stringdate);
	}
	function _formatDateYMDtoDMY($stringdate,$format)
	{
		return $this->getday($stringdate).$format.$this->getmonth($stringdate).$format.$this->getyear($stringdate);
	}
	function _formatDateDMYtoYMD( $stringdate )
	{
		$y=substr($stringdate,6,4);  
		$m=substr($stringdate,3,2);
		$d=substr($stringdate,0,2);
		return $y."-".$m."-".$d;
	}
	function _formatDateMDYtoYMD( $stringdate )
	{
		$y=substr($stringdate,6,4);  
		$d=substr($stringdate,3,2);
		$m=substr($stringdate,0,2);
		return $y."-".$m."-".$d;
	}
	
	function _formatDateDDMMYY( $stringdate ) 
	{
		$d=strrev(substr(strrev($stringdate),0,2));
		$m=strrev(substr(strrev($stringdate),3,2));
		$y=strrev(substr(strrev($stringdate),6,4));
		return $d."-".$m."-".$y;
	}
	
	function _fDateDDMMYY( $stringdate, $format ) 
	{
		$d=strrev(substr(strrev($stringdate),0,2));
		$m=strrev(substr(strrev($stringdate),3,2));
		$y=strrev(substr(strrev($stringdate),6,4));
		return $d.$format.$m.$format.$y;
	}
	
	function _getTime( $stringdatetime )
	{
		$time = substr($stringdatetime,11,19);  
		return $time;
	}
	function _getDateNow($formate)
	{
		$today = getdate();
		
		$time = $this->formate($today['year']).$formate.$this->formate($today['mon']).$formate.$this->formate($today['mday']);
		return $time;
	}
	function _getDateNowDMY($formate)
	{
		$today = getdate();
		
		$time = $this->formate($today['mday']).$formate.$this->formate($today['mon']).$formate.$this->formate($today['year']);
		return $time;
	}
	function _getTimeNow()
	{
		$today = getdate();
		
		$time = $this->formate($today['hours']).":".$formate.$this->formate($today['minutes']).":".$formate.$this->formate($today['seconds']);
		return $time;
	}
	function _getNow($formate)
	{
		return $this->_getDateNow($formate)." ".$this->_getTimeNow();
	}
	function _getDayNow()
	{
		$today = getdate();
		return $today['mday'];
	}
	function _getMonthNow()
	{
		$today = getdate();
		return $today['mon'];
	}
	function _getYearhNow()
	{
		$today = getdate();
		return $today['year'];
	}
	function _getDate( $stringdatetime )
	{
		$date = substr($stringdatetime,0,10);  
		return $date;
	}
	
	function _getYear( $stringdatetime )
	{
		$year = substr($stringdatetime,6,10);  
		return $year;
	}
	
	function _compareDate($PresentDate,$ExpiredDate)
	{
		$da=split("-",$PresentDate);
		$PreYear = $da[0];
		$PreMonth = $da[1];
		$PreDate = $da[2];

		$da1=split("-",$ExpiredDate);
		$ExpYear = $da1[0];
		$ExpMonth = $da1[1];
		$ExpDate = $da1[2];
		if($ExpYear>$PreYear)
			return 1;
		elseif(($ExpYear==$PreYear) && ($ExpMonth > $PreMonth))
			return 1;
		elseif(($ExpYear==$PreYear) && ($ExpMonth==$PreMonth) && ($ExpDate > $PreDate))
			return 1;
		else
			return 0;
	}
	function getday($stringdate)//fomate yy-mm-dd
	{
		$d=substr($stringdate,8,2);
		return $d;
	}
	function getmonth($stringdate)//fomate yy-mm-dd
	{
		$m=substr($stringdate,5,2);  
		return $m;
	}
	function getyear($stringdate)//fomate yy-mm-dd
	{
		$y=substr($stringdate,0,4);  
		return $y;
	}
	function gethoure($stringdate)//fomate yy-mm-dd
	{
		$h=substr($stringdate,11,2);  
		return $h;
	}
	function getmin($stringdate)//fomate yy-mm-dd
	{
		$m=substr($stringdate,14,2);  
		return $m;
	}
	function getsec($stringdate)//fomate yy-mm-dd
	{
		$s=substr($stringdate,17,2);  
		return $s;
	}
	function addday($stringdate,$days) //fomate yy-mm-dd
	{
		
		//string date ( string $format [, int $timestamp] )
		//mktime(0,0,0,
		$d=$this->getday($stringdate);
		$mon=$this->getmonth($stringdate);
		$y=$this->getyear($stringdate);
		$time = mktime(0,0,0,intval($mon),intval($d)+$days,intval($y));
		return date("Y-m-d",$time);
	}
	function addmonth($stringdate,$months) //fomate yy-mm-dd
	{
		
		//string date ( string $format [, int $timestamp] )
		//mktime(0,0,0,
		$d=$this->getday($stringdate);
		$mon=$this->getmonth($stringdate);
		$y=$this->getyear($stringdate);
		$time = mktime(0,0,0,intval($mon)+$months,intval($d),intval($y));
		return date("Y-m-d",$time);
	}
	function addyear($stringdate,$years) //fomate yy-mm-dd
	{
		
		//string date ( string $format [, int $timestamp] )
		//mktime(0,0,0,
		$d=$this->getday($stringdate);
		$mon=$this->getmonth($stringdate);
		$y=$this->getyear($stringdate);
		$time = mktime(0,0,0,intval($mon),intval($d),intval($y)+$years);
		return date("Y-m-d",$time);
	}
	function addhour($stringdate,$hour) //fomate yy-mm-dd
	{
		
		//string date ( string $format [, int $timestamp] )
		//mktime(0,0,0,
		$d=$this->getday($stringdate);
		$mon=$this->getmonth($stringdate);
		$y=$this->getyear($stringdate);
		
		$h=$this->gethoure($stringdate);
		$m=$this->getmin($stringdate);
		$s=$this->getsec($stringdate);
		$time = mktime(intval($h + $hour),intval($m),intval($s),intval($mon),intval($d),intval($y));
		return date("Y-m-d  H:i:s",$time);
	}
	function addminutes($stringdate,$minutes) //fomate yy-mm-dd
	{
		
		//string date ( string $format [, int $timestamp] )
		//mktime(0,0,0,
		$d=$this->getday($stringdate);
		$mon=$this->getmonth($stringdate);
		$y=$this->getyear($stringdate);
		
		$h=$this->gethoure($stringdate);
		$m=$this->getmin($stringdate);
		$s=$this->getsec($stringdate);
		$time = mktime(intval($h),intval($m) + $minutes,intval($s),intval($mon),intval($d),intval($y));
		return date("Y-m-d H:i:s",$time);
	}
	function addsec($stringdate,$sec) //fomate yy-mm-dd
	{
		
		//string date ( string $format [, int $timestamp] )
		//mktime(0,0,0,
		$d=$this->getday($stringdate);
		$mon=$this->getmonth($stringdate);
		$y=$this->getyear($stringdate);
		
		$h=$this->gethoure($stringdate);
		$m=$this->getmin($stringdate);
		$s=$this->getsec($stringdate);
		$time = mktime(intval($h),intval($m),intval($s)+$sec,intval($mon),intval($d),intval($y)+$years);
		return date("Y-m-d  H:i:s",$time);
	}
	function isDate($year,$mon,$day)
	{
		$time = mktime(0,0,0,intval($mon),intval($day),intval($year));
		$da1=$year."-".$mon."-".$day;
		$da2= date("Y-m-d",$time);
		if($this->_compareDate($da1,$da2)==0)
			return true;
		else false;
	}
	
	function formate($num)
	{
		if( $num <10 )
			return "0".$num;
		return $num;
	}
}
?>
